<?php
namespace CTCF;
/**
 *  控制器基类 抽象类
 */
abstract class Controller {
    protected $config   =   array();
    protected $_view = '';
    protected $_M;
    public function __construct($runModel) {
    	if($runModel == 2){
    		//加载模版引擎
    		require_once APP.'/Conf/smarty.config.php';
    		require_once SMARTY_DIR.'Smarty.class.php';
    		$this->_view = new \Smarty();
    		$this->_view->template_dir = SMARTY_TMPL_DIR;
    		$this->_view->compile_dir = SMARTY_COMPLIE_DIR;
    		$this->_view->config_dir = SMARTY_CONFIG_DIR;
    		$this->_view->cache_dir = SMARTY_CACHE_DIR;  
    		$this->_view->caching = TMPL_CACHE;
    		$this->_view->left_delimiter = SMARTY_LEFT_DELIMITER;  		
    		$this->_view->right_delimiter = SMARTY_RIGHT_DELIMITER;  		
    	}
    	
    	spl_autoload_register(function ($class) {
    		if (strpos($class, '\\')) {
    			$urls = explode('\\', $class);    			 
    			$class = str_replace('\\', '/', $class);
				$file = './Core/Lib/'.$class.'.class.php';
    			if (file_exists($file)) {
    				include $file;
    			}
    		}
    	});
    }
    
     protected function display($tpl){
     	$this->_view->display(VIEW.'/'.$tpl);
     }

     protected function assign($name,$value='') {
     	$this->_view->assign($name,$value);
     	return $this;
     }
     
     public function __set($name,$value) {
     	$this->assign($name,$value);
     }
     
     /**
      * 取得模板显示变量的值
      * @access protected
      * @param string $name 模板显示变量
      * @return mixed
      */
     public function get($name='') {
     	return $this->_view->get($name);
     }
     
     public function __get($name) {
     	return $this->get($name);
     }
     
     /**
      * 检测模板变量的值
      * @access public
      * @param string $name 名称
      * @return boolean
      */
     public function __isset($name) {
     	return $this->get($name);
     }
      
     
     
      
     public function __destruct() {
        // 执行后续操作
       
    }
    
    
}
